T <- 72 # for count data

# ZEROS TRICK
zeros <- rep(0,T)
Up2 <- 1000
Up4 <- 1000
X2_prior <- rep(1/(Up2+1), Up2+1) 
X4_prior <- rep(1/(Up4+1), Up4+1) 

# HMM
N_max1 = 79
N_max3 = 49
sc = 100


# Ring-recovery data:
ring1 <- 43

m1 <- matrix(c(
  348, 33, 5, 0, 0, 3, 4, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  141,  0,17, 6, 4, 2, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  265,  0, 0,31,12, 2, 2, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  80,   0, 0, 0,12, 3, 2, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  335,  0, 0, 0, 0,34,22, 7, 7, 1, 2, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  98,   0, 0, 0, 0, 0, 5, 6, 4, 0, 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  170,  0, 0, 0, 0, 0, 0,23, 7, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,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0, 0, 0, 0, 0, 0, 0, 53, 18,  6,  0,  0,  1, 2, 0, 3,  0, 0,  0,  0, 0, 0, 1, 0, 1,  0, 0,  0,  0, 0, 0, 0, 0, 0, 0, 0,
  476,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 39, 16,  8,  6,  3, 3, 2, 3,  1, 2,  0,  0, 0, 0, 0, 0, 0,  0, 0,  0,  0, 0, 0, 0, 0, 0, 0, 0,
  446,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0, 31, 17,  4,  6, 1, 2, 0,  0, 0,  0,  0, 0, 0, 0, 0, 2,  0, 0,  0,  0, 0, 1, 0, 0, 0, 0, 0,
  282,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0, 23, 14,  4, 0, 1, 1,  0, 0,  2,  0, 0, 0, 0, 0, 0,  0, 0,  0,  0, 0, 0, 0, 0, 0, 0, 0,
  236,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0, 32,  5, 4, 2, 0,  0, 1,  0,  1, 0, 0, 0, 0, 0,  0, 0,  0,  0, 0, 0, 0, 0, 0, 0, 0,
  282,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0, 10, 0, 6, 2,  0, 1,  1,  0, 0, 1, 0, 0, 0,  0, 0,  0,  0, 0, 0, 0, 0, 0, 0, 0,
  450,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0,30, 7, 3,  0, 1,  0,  0, 1, 1, 0, 1, 0,  0, 0,  1,  0, 0, 0, 0, 0, 0, 0, 0,
  589,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0, 0,49, 7,  4, 1,  1,  0, 1, 1, 0, 0, 0,  0, 0,  1,  0, 0, 0, 0, 0, 0, 0, 0,
  464,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0,33, 13, 5,  2,  1, 1, 0, 0, 0, 0,  0, 0,  1,  0, 0, 0, 0, 0, 0, 1, 0,
  237,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0, 20, 4,  0,  2, 2, 0, 0, 0, 0,  2, 0,  0,  0, 0, 0, 0, 0, 0, 0, 0,
  434,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0,  0, 32,13, 12, 0, 2, 4, 1, 0,  0, 0,  0,  0, 0, 0, 1, 1, 0, 0, 0,
  648,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0,  0,  0,35, 13, 7, 0, 2, 1, 0,  1, 0,  0,  0, 0, 0, 0, 0, 0, 1, 0, 
  740,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0,  0,  0, 0, 44, 5, 6, 1, 0, 0,  0, 0,  1,  0, 0, 2, 0, 0, 0, 0, 0, 
  1014, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0,  0,  0, 0,  0,41,11, 3, 5, 5,  5, 1,  0,  1, 2, 0, 0, 1, 0, 1, 0, 
  777,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0,  0,  0, 0,  0, 0,30, 6, 7, 1,  2, 3,  1,  1, 0, 0, 1, 0, 0, 0, 0,  
  1110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0,  0,  0, 0,  0, 0, 0,59,22, 9,  1, 1,  0,  0, 1, 1, 0, 1, 0, 1, 0,  
  814,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0,  0,  0, 0,  0, 0, 0, 0,50,10,  2, 3,  0,  0, 3, 0, 1, 1, 0, 0, 0,  
  732,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0,  0,  0, 0,  0, 0, 0, 0, 0,24, 11, 2,  3,  2, 1, 0, 0, 1, 0, 0, 0, 
  578,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0,  0,  0, 0,  0, 0, 0, 0, 0, 0, 20, 6,  3,  3, 3, 1, 0, 0, 1, 1, 1,  
  498,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0,  0,  0, 0,  0, 0, 0, 0, 0, 0,  0,11,  8,  5, 2, 2, 0, 1, 1, 0, 1, 
  527,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0,  0,  0, 0,  0, 0, 0, 0, 0, 0,  0, 0, 18, 12, 1, 4, 2, 1, 3, 0, 2, 
  596,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0,  0,  0, 0,  0, 0, 0, 0, 0, 0,  0, 0,  0, 28, 5, 2, 3, 0, 2, 0, 0,
  492,	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0,  0,  0, 0,  0, 0, 0, 0, 0, 0,  0, 0,  0,  0,10, 6, 3, 0, 1, 1, 0,
  565,	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0,  0,  0, 0,  0, 0, 0, 0, 0, 0,  0, 0,  0,  0, 0,21, 2, 0, 0, 0, 1,
  572,	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0,  0,  0, 0,  0, 0, 0, 0, 0, 0,  0, 0,  0,  0, 0, 0,26, 5, 2, 1, 1,
  576,	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0,  0,  0, 0,  0, 0, 0, 0, 0, 0,  0, 0,  0,  0, 0, 0, 0,20, 6, 3, 1,
  683,	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0,  0,  0, 0,  0, 0, 0, 0, 0, 0,  0, 0,  0,  0, 0, 0, 0, 0,23, 5, 2,
  510,	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0,  0,  0, 0,  0, 0, 0, 0, 0, 0,  0, 0,  0,  0, 0, 0, 0, 0, 0,16, 0,
  718,	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0,  0,  0, 0,  0, 0, 0, 0, 0, 0,  0, 0,  0,  0, 0, 0, 0, 0, 0, 0,18), 
  nrow=43,ncol=44,byrow=T)  

# m <- array(0,dim=c(43,44))
# rel <- array(0,ring1)

m <- cbind(m1[,2:(ring1+1)],m1[,1]-rowSums(m1[,2:(ring1+1)]))
# for (i in 1:ring1) {
#   for (j in 1:ring1) {
#     m[i,j] <- m1[i,j+1] 
#   }
#   m[i,(ring1+1)] <- m1[i,1]-sum(m1[i,2:(ring1+1)])
#   # rel[i] <- sum(m[i,])
# }

m[,(ring1+1)] = round(m[,(ring1+1)]/sc)
rel <- rowSums(m)


# Count data:

# T <- 72

y <- round(c(0,4000, 3500, 3850, 4050, 4000, 4075, 4150, 4150, 4375, 4500, 4800, 4700, 3650, 3550, 3400, 3850, 4300, 
       4075, 4125, 2700, 2800, 3575, 4100, 4550, 4700, 4575, 4800, 4425, 4150, 4500, 4075, 4550, 4350, 4675,
       3700, 2250, 2450, 2825, 2925, 3225, 3725, 3925, 4125, 4575, 4625, 4925, 5175, 5100, 5075, 5125, 5375, 
       5200, 5575, 5675, 5350, 5425, 5700, 5775, 5109, 5166, 5637, 5898, 6143, 5936, 6051, 6310, 6447, 6950, 
       6570, 6653, 6940)/sc)


# Starting in T=1 = 1927
# T=2 = first year of count data (1928)
# T=28 = first year of ring-recovery data (1955)
fdays <- c(12, 26, 2, 9, 6, 8, 3, 2, 17, 3, 4, 8, 38, 12, 30, 3, 2, 15, 18, 46, 6,  
           3, 6, 15, 6, 13, 17, 22, 22, 4, 11, 9, 2, 1, 22, 57, 12, 13, 13, 2, 15, 
           13, 20, 12, 3, 1, 5, 0, 6, 9, 11, 33, 7, 2, 27, 5, 7, 25, 30, 16, 3, 1,  
           1, 12, 12, 9, 6, 3, 18, 10, 0, 1)

# Normalise fdays:
f <- (fdays-mean(fdays))/sd(fdays)

# Time (for recovery probability regression) - normalised.
# time <- c(1:T)
time <- c(1:ring1)
time <- (time-mean(time))/sd(time)

data <- list(y=y,T=T,m=m,ring1=ring1,f=f,time=time,rel=rel, zeros=zeros, N_max1=N_max1, N_max3=N_max3, X2_prior=X2_prior, X4_prior=X4_prior)